package com.ruoyi.ai.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.ai.domain.AiDialogue;
import com.ruoyi.ai.service.IAiDialogueService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 对话管理Controller
 *
 * @author ai
 * @date 2024-12-12
 */
@RestController
@RequestMapping("/ai/dialogue")
public class AiDialogueController extends BaseController
{
    @Autowired
    private IAiDialogueService aiDialogueService;

    /**
     * 查询对话管理列表
     */
    @PreAuthorize("@ss.hasPermi('ai:dialogue:list')")
    @GetMapping("/list")
    public TableDataInfo list(AiDialogue aiDialogue)
    {
        startPage();
        List<AiDialogue> list = aiDialogueService.selectAiDialogueList(aiDialogue);
        return getDataTable(list);
    }

    /**
     * 导出对话管理列表
     */
    @PreAuthorize("@ss.hasPermi('ai:dialogue:export')")
    @Log(title = "对话管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, AiDialogue aiDialogue)
    {
        List<AiDialogue> list = aiDialogueService.selectAiDialogueList(aiDialogue);
        ExcelUtil<AiDialogue> util = new ExcelUtil<AiDialogue>(AiDialogue.class);
        util.exportExcel(response, list, "对话管理数据");
    }

    /**
     * 获取对话管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('ai:dialogue:query')")
    @GetMapping(value = "/{dialogueId}")
    public AjaxResult getInfo(@PathVariable("dialogueId") String dialogueId)
    {
        return success(aiDialogueService.selectAiDialogueByDialogueId(dialogueId));
    }

    /**
     * 新增对话管理
     */
    @PreAuthorize("@ss.hasPermi('ai:dialogue:add')")
    @Log(title = "对话管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@Validated @RequestBody AiDialogue aiDialogue)
    {
        return toAjax(aiDialogueService.insertAiDialogue(aiDialogue));
    }

    /**
     * 修改对话管理
     */
    @PreAuthorize("@ss.hasPermi('ai:dialogue:edit')")
    @Log(title = "对话管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@Validated @RequestBody AiDialogue aiDialogue)
    {
        return toAjax(aiDialogueService.updateAiDialogue(aiDialogue));
    }

    /**
     * 删除对话管理
     */
    @PreAuthorize("@ss.hasPermi('ai:dialogue:remove')")
    @Log(title = "对话管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{dialogueIds}")
    public AjaxResult remove(@PathVariable String[] dialogueIds)
    {
        return toAjax(aiDialogueService.deleteAiDialogueByDialogueIds(dialogueIds));
    }
}
